import { makeDurableObject, makeWorker } from "@livestore/sync-cf/cf-worker";

export class WebSocketServer extends makeDurableObject({
  onPush: async (message) => {
    console.log("onPush", message.batch);
  },
  onPull: async (message) => {
    console.log("onPull", message);
  },
}) {}

export default makeWorker({
  validatePayload: (payload: any) => {
    if (payload?.authToken !== "insecure-token-change-me") {
      throw new Error("Invalid auth token");
    }
  },
  enableCORS: true,
});
